<%= form_for [@project, @kubernetes_deploy_group_role], html: { class: "form-horizontal" } do |form| %>
  <%= redirect_to_field %>
  <%= render 'shared/errors', object: form.object %>
  <%
    defaults = form.object.kubernetes_role&.defaults || {} rescue {}
    updating = form.object.persisted?
  %>

  <fieldset>
    <%= form.input :deploy_group_id do %>
      <%= form.select :deploy_group_id, DeployGroup.pluck(:name, :id), {}, class: "form-control", disabled: updating %>
    <% end %>

    <%= form.input :kubernetes_role_id, label: 'Role' do %>
      <% roles = @project.kubernetes_roles.not_deleted.pluck(:name, :id) %>
      <%= form.select :kubernetes_role_id, roles, {}, class: "form-control", disabled: updating %>
    <% end %>

    <%= form.input :delete_resource, as: :check_box, help: "Delete all resources on next deploy. Always set replicas to 0 too." %>

    <% if Kubernetes::DeployGroupRole::NO_CPU_LIMIT_ALLOWED %>
      <%= form.input :no_cpu_limit, as: :check_box, help: "Cpu limit will not be set when deploying, but still be used for cluster math, so pick a good estimate." %>
    <% end %>

    <%# display fields and their suggested defaults %>
    <% [
         [:replicas, @kubernetes_deploy_group_role.kubernetes_role&.autoscaled? ? "Min Replicas" : "Replicas"],
         [:requests_cpu, 'Requests CPU Cores'],
         [:requests_memory, 'Requests Memory in MiB'],
         [:limits_cpu, 'Limits CPU Cores'],
         [:limits_memory, 'Limits Memory in MiB']
       ].each do |column, label| %>
      <%= form.input column, label: label do %>
        <%= form.text_field column, class: "form-control", required: true %>
        <% if default = defaults[column] %>
          Default: <%= default %>
        <% end %>
      <% end %>
    <% end %>

    <% if show_istio_sidecar_ui? %>
      <%= form.input :inject_istio_annotation, as: :check_box, help: "Add an annotation to the Pod template which should cause Istio to inject a sidecar proxy." %>
    <% end %>

    <%# TODO: use form.actions with delete: true, history: true and block %>
    <div class="form-group">
      <div class="col-lg-offset-2 col-lg-10">
        <%= form.submit 'Save', class: "btn btn-primary" %>
        <%= submit_tag ResourceController::ADD_MORE, class: 'btn btn-default' %>
        <%= link_to_delete [@project, form.object], class: 'btn btn-default', redirect_back: true if form.object.persisted? %>
        <%= link_to "Cancel", :back, class: 'btn btn-default' %>
        <%= link_to_history form.object %>
      </div>
    </div>
  </fieldset>
<% end %>
